<template>
  <el-carousel :interval="4000" type="card" height="150px" width="100%">
    <!-- <el-carousel-item v-for="(item,index)  in list" :key="index">
      <h3 class="medium">
        <img :src="item.url" width="100%" height="150px" />
      </h3>
    </el-carousel-item> -->


    <el-carousel-item v-for="obj in list" :key="obj.bannerid">
      <h3 class="medium">
        <img :src="obj.img" width="100%" height="150px" @click="goUrl(obj.link)"/>
      </h3>
    </el-carousel-item>
  </el-carousel>
</template>

<script>
import axios from "axios";

export default {
  name: "Banner",
  data() {
    return {
      // list: [
      //   {url:"https://chengqige-7gunki87efeca981-1302748923.tcloudbaseapp.com/1024/2.jpg"},
      //   {url:"https://chengqige-7gunki87efeca981-1302748923.tcloudbaseapp.com/1024/6.jpg"},
      //   {url:"https://chengqige-7gunki87efeca981-1302748923.tcloudbaseapp.com/1024/7.jpg"},
      //   {url:"https://chengqige-7gunki87efeca981-1302748923.tcloudbaseapp.com/1024/12.jpg"}
      // ]
      imgs:[],
    };
  },
  created(){
    axios({
      url: "/api/banner/list",
    }).then((res) => {
      let data = res.data;
      if(data.code==200){
        this.imgs = data.data
      }

     });
  },
   computed:{
    list:function(){
      return this.imgs.filter(item=>item.flag)
    }
  },
  methods:{
     goUrl(url){
      location.href=url;
    }
  }
};
</script>

<style scoped>
.el-carousel {
  position: relative;
}

.el-carousel__item {
  position: absolute;
  left: -4rem;
}
.el-carousel__item h3 {
  /* color: #475669; */
  font-size: 14px;
  opacity: 1;
  line-height: 200px;
  /* padding-top: .625rem; */
  margin: 0;
  
}

.el-carousel__item:nth-child(2n) {
  background-color: #99a9bf;
  position: absolute;
  left: -1.25rem;
  width: 15.625rem;
}

.el-carousel__item:nth-child(2n + 1) {
  background-color: #d3dce6;
  position: absolute;
  left: -1.25rem;
  width: 15.625rem;
}
</style>